<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <style>
        .v-enter,
        .v-leave-to {
            opacity: 0;
        }

        .v-enter-active,
        .v-leave-active {
            transition: opacity 3s;
        }
    </style>
</head>

<body>
    <div id="root">
        <fade :show="show">
            <div>hello world</div>
        </fade>
        <button @click="handleClick">切换</button>
    </div>
    <script>
        Vue.component( 'fade', {
            props: [ 'show' ],
            template: `
            <transition>
                <slot v-if="show"></slot>
                </transition>
            `
        } )
        var vm = new Vue( {
            el: '#root',
            data: {
                show: true
            },
            methods: {
                handleClick: function () {
                    this.show = !this.show
                }
            }
        } )
    </script>
</body>

</html>